package com.lowang.test.springmvc.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lowang.test.springmvc.domain.User;
import com.lowang.test.springmvc.service.IUserService;

@RestController("userController")
@RequestMapping("/user")
public class UserController {

  private IUserService userService;

  @Autowired
  public void setUserService(IUserService userService) {
    this.userService = userService;
  }

  @RequestMapping("/list")
  public List<User> list(User user) {

    return userService.list(user);
  }

  @RequestMapping("/add")
  public User add(@RequestBody User user) {
    return userService.add(user);
  }

  @RequestMapping("/update")
  public User update(User user) {

    return userService.update(user);
  }

  @RequestMapping("/delete/{id}")
  public User delete(@PathVariable(name = "id", required = true) Long id) {
    return userService.delete(id);
  }
}
